package com.allenkerr.service.impl;


import com.allenkerr.dao.CustomerRepository;
import com.allenkerr.model.Customer;
import com.allenkerr.service.CustomerService;
import com.allenkerr.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerRepository customerDao;

    @Override
    public Result saveCustomers(List<Customer> customers) {
        Iterable<Customer> savedCustomers = customerDao.save(customers);
        if (savedCustomers != null) {
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Iterator<Customer> findAllCustomers() {
        Iterable<Customer> allCustomers = customerDao.findAll();
        return allCustomers.iterator();
    }

    @Override
    public List<Customer> findCustomersByFirstName(String firstName) {
        List<Customer> customers = customerDao.findByFirstName(firstName);
        return customers;
    }

    @Override
    public List<Customer> findCustomersByLastName(String lastName) {
        List<Customer> customers = customerDao.findByFirstName(lastName);
        return customers;
    }
}